/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
 var oddEvenList = function(head) {
    if(head==null || head.next==null){
        return head;
    }
    let nextnode=head.next;
    let nlist=head;
    let newlist = new ListNode;
    for(let i=2;nextnode!=null;i++){
        if(i%2==1){
            nlist=nlist.next;
            nextnode=nextnode.next;
        }
        else{
            newlist.next=nextnode;
            nlist.next=nextnode.next == null ? nlist : nextnode.next;
            newlist=newlist.next;
            nextnode=nextnode.next;
        }
    }
    nlist.next=newlist.next;
    return head;
};